package history.study.array;

// 704. 二分查找:https://leetcode-cn.com/problems/binary-search/
public class LeetCode_704 {
    public int search(int[] nums, int target) {
        if (nums.length <=0) return -1;
        int left = 0, right = nums.length-1;
        while (left <= right) {
            int mid = left + ((right-left)>>1);
            if (nums[mid] == target) return mid;
            if (nums[mid] < target) {
                left = mid+1;
            } else {
                right = mid-1;
            }
        }
        return -1;
    }
}
